<?php

class branch_Model_DbTable_DbBranch extends Zend_Db_Table_Abstract
{
	protected $_name ="tbwu_branch";
	
	public function getAllBranch(){
		$db = $this->getAdapter();
		$sql = "SELECT b.*,l.`location_name` FROM tbwu_branch AS b,`tbwu_location` AS l WHERE b.`location_id`=l.`location_id`";
		return $db->fetchAll($sql);
	}
	public function getBranchById($data){
		$db = $this->getAdapter();
		$sql = "SELECT b.* FROM tbwu_branch AS b WHERE b.branch_id = $data";
		return $db->fetchRow($sql);
	}
    public function addBranch($data)
    {
    	try {
	    	$arr = array(
	    		'location_id'		=>	$data["location"],
	    		'branch_name'		=>	$data["branch"],
	    		'branch_address'	=>	$data["address"],
	    		'description'		=>	$data["description"],
	    		'created_date'		=>	new Zend_Date(),
	    		'user_id'			=>	1,
	    		'status'			=>	$data["status"]
	    	);
	    	//$this->_name = "tbwu_branch";
	    	$this->insert($arr);
    	}catch (Exception $e){
    		echo $e->getMessage();
    		exit();
    	}
    }
    public function editBranch($data){
    	$db = $this->getAdapter();
    	$id = $data["id"];
    	try {
	    	$arr = array(
	    			'location_id'		=>	$data["location"],
	    			'branch_name'		=>	$data["branch"],
	    			'branch_address'	=>	$data["address"],
	    			'description'		=>	$data["description"],
	    			'created_date'		=>	new Zend_Date(),
	    			'user_id'			=>	1,
	    			'status'			=>	$data["status"]
	    	);
	    	//$this->_name = "tbwu_branch";
	    	$where = $db->quoteInto("branch_id=?", $id);
	    	$this->update($arr, $where);
    	}catch (Exception $e){
    		echo $e->getMessage();
    		exit();
    	}
    }
}

